package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.GrogshopRoom;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IGrogshopRoomService;
import cn.wolfcode.trip.base.service.IGrogshopService;
import cn.wolfcode.trip.base.service.IRoomService;
import cn.wolfcode.trip.base.util.JsonResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 *酒店管理控制器
 */
@Controller
@RequestMapping("grogshopRoom")
public class GrogshopRoomController {
    @Autowired
    private IGrogshopService grogshopService;
    @Autowired
    private IGrogshopRoomService grogshopRoomService;
    @Autowired
    private IRoomService roomService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo")QueryObject qo, Model model){

        model.addAttribute("pageInfo",grogshopRoomService.query(qo));
        model.addAttribute("grogshop",grogshopService.listAll());
        model.addAttribute("room",roomService.listAll());
        return "grogshopRoom/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(MultipartFile file, GrogshopRoom grogshopRoom){
        JsonResult jsonResult = new JsonResult();
        if (file!=null && file.getSize()>0){
            //保存封面图片
            String url = UploadUtil.uploadQiniu(file);
            //把url设置到coverUrl属性
            grogshopRoom.setCoverUrlGR(url);
        }
        grogshopRoomService.saveOrUpdate(grogshopRoom);
        return jsonResult;
    }
}
